package online.chazi.bootplus.autoconfiguation.multiple.datasource.mybatis.plus;

import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
import online.chazi.bootplus.autoconfiguation.multiple.datasource.MultipleDataSourceConfig;
import online.chazi.bootplus.multiple.datasource.MultipleDataSource;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;

import javax.annotation.Resource;

/**
 * 说明：作者很懒，什么都没留下
 * Created by 叉子同学 on 2020-05-18 15:33
 */
@Configuration
@AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE)
@AutoConfigureAfter(MultipleDataSourceConfig.class)
public class MybatisSqlSessionFactoryConfig {

    @Resource
    private MultipleDataSource multipleDataSource;

    @Bean
    @ConditionalOnBean(MultipleDataSource.class)
    public MybatisSqlSessionFactoryBean sqlSessionFactory() {
        MybatisSqlSessionFactoryBean factoryBean = new MybatisSqlSessionFactoryBean();
        factoryBean.setDataSource(multipleDataSource);
        return factoryBean;
    }

}
